# -*- coding: utf-8 -*-

from multiprocessing import Process, current_process
import time

def task():
    print('%s is running' % current_process().pid)
    time.sleep(3)
    print('%s is done' % current_process().pid)

if __name__ == '__main__':
    p1 = Process(target=task)
    p1.start()
    print(p1.name)   # 进程的名字
    p1.terminate()   # 杀死子进程
    time.sleep(0.1)  # 操作需要时间
    print(p1.is_alive())  # 判断子进程是否存活
    print('%s 主进程' % current_process().pid)
    '''
    运行结果：根据计算机实际运行情况，结果可能不一致
    Process-1
    False
    4592 主进程
    '''